' LTC2983 Test Program for MM+470 on the GC microboard 2

Option explicit

' Assign Object Values

Const status_button=1
Const data_button=2
Const setup_button=3

Const cht1_led=4
Const cht2_led=5
Const cht3_led=6
Const cht4_led=7
Const egt1_led=8
Const egt2_led=9
Const egt3_led=10
Const egt4_led=11

Const temps_stat_frame=12
Const cht_stat_box=13
Const egt_stat_box=14

Const cht_data_frame=15
Const cht1_data_box=16
Const cht2_data_box=17
Const cht3_data_box=18
Const cht4_data_box=19

Const egt_data_frame=20
Const egt1_data_box=21
Const egt2_data_box=22
Const egt3_data_box=23
Const egt4_data_box=24

Const cht_thermo_type_frame=25
Const cht_jtype_button=26
Const cht_ktype_button=27

Const egt_thermo_type_frame=28
Const egt_jtype_button=29
Const egt_ktype_button=30

Const rpm_count_frame=31
Const rpm_dev2_button=32
Const rpm_even_button=33
Const rpm_mul2_button=34
Const rpm_mul4_button=35
Const rpm_dis_button=36


Dim screen_state=status_button ' current value of active screen objects
Dim old_screen_state,touch_state
Font #5,1

CLS

GUI button status_button,"Status",0,0,MM.FontWidth*7,MM.FontHeight*2,RGB(yellow),RGB(gray)
GUI button data_button,"Data",127,0,MM.FontWidth*5,MM.FontHeight*2,RGB(yellow),RGB(gray)
GUI button setup_button,"Setup",220,0,MM.FontWidth*6,MM.FontHeight*2,RGB(yellow),RGB(gray)

' Create "Status Screen"

GUI frame temps_stat_frame,"Temps",0,75,320,125,RGB(yellow)
GUI displaybox cht_stat_box,7,100,MM.FontWidth*19,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(cht_stat_box)="CHT  1  2  3  4"
GUI led cht1_led,139,104,20,RGB(green)
GUI led cht2_led,188,104,20,RGB(red)
GUI led cht3_led,237,104,20,RGB(yellow)
GUI led cht4_led,285,104,20,RGB(yellow)

GUI displaybox egt_stat_box,7,150,MM.FontWidth*19,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(egt_stat_box)="EGT  1  2  3  4"
GUI led egt1_led,139,154,20,RGB(green)
GUI led egt2_led,188,154,20,RGB(green)
GUI led egt3_led,237,154,20,RGB(green)
GUI led egt4_led,285,154,20,RGB(green)

GUI hide temps_stat_frame,cht_stat_box,egt_stat_box
GUI hide cht1_led,cht2_led,cht3_led,cht4_led
GUI hide egt1_led,egt2_led,egt3_led,egt4_led

' Create "Data" Screen

GUI frame cht_data_frame," CHT ",0,75,110,159,RGB(yellow)
GUI displaybox cht1_data_box,15,90,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(cht1_data_box)="xxx"
GUI displaybox cht2_data_box,15,125,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(cht2_data_box)="xxx"
GUI displaybox cht3_data_box,15,160,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(cht3_data_box)="xxx"
GUI displaybox cht4_data_box,15,195,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(cht4_data_box)="xxx"

GUI frame egt_data_frame," EGT ",115,75,110,159,RGB(yellow)
GUI displaybox egt1_data_box,130,90,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(egt1_data_box)="xxxx"
GUI displaybox egt2_data_box,130,125,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(egt2_data_box)="xxxx"
GUI displaybox egt3_data_box,130,160,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(egt3_data_box)="xxxx"
GUI displaybox egt4_data_box,130,195,MM.FontWidth*5,MM.FontHeight+5,RGB(red),RGB(black)
CtrlVal(egt4_data_box)="xxxx"

GUI hide cht_data_frame,egt_data_frame
GUI hide cht1_data_box,cht2_data_box,cht3_data_box,cht4_data_box
GUI hide egt1_data_box,egt2_data_box,egt3_data_box,egt4_data_box

' Create "Settup" Screen

GUI frame cht_thermo_type_frame,"CHT",0,75,80,70,RGB(yellow)
GUI radio cht_jtype_button,"J",15,85,25,RGB(green)
GUI radio cht_ktype_button,"K",15,115,25,RGB(green)
CtrlVal(cht_jtype_button)=1

GUI frame egt_thermo_type_frame,"EGT",0,165,80,70,RGB(yellow)
GUI radio egt_jtype_button,"J",15,175,25,RGB(green)
GUI radio egt_ktype_button,"K",15,205,25,RGB(green)
CtrlVal(egt_jtype_button)=1

GUI frame rpm_count_frame,"RPM",85,75,95,160,RGB(yellow)
GUI radio rpm_dev2_button,"\2",100,85,25,RGB(green)
GUI radio rpm_even_button,"EV",100,115,25,RGB(green)
GUI radio rpm_mul2_button,"x2",100,145,25,RGB(green)
GUI radio rpm_mul4_button,"x4",100,175,25,RGB(green)
GUI radio rpm_dis_button,"DS",100,205,25,RGB(green)
CtrlVal(rpm_dis_button)=1

GUI hide cht_thermo_type_frame,egt_thermo_type_frame
GUI hide cht_jtype_button,cht_ktype_button
GUI hide egt_jtype_button,egt_ktype_button
GUI hide rpm_count_frame,rpm_dev2_button,rpm_even_button
GUI hide rpm_mul2_button,rpm_mul4_button,rpm_dis_button

'End

' set some values...

CtrlVal(cht1_led)=1
CtrlVal(cht2_led)=1
CtrlVal(cht3_led)=1
CtrlVal(cht4_led)=1
CtrlVal(egt2_led)=1

GUI interrupt TouchDown,TouchUp
SetTick 1000,blink

' ----------- Main

Do
If screen_state<>old_screen_state Then redraw
Loop

' -------- Sub's

Sub blink
If CtrlVal(cht1_led) Then
  CtrlVal(cht1_led)=0
  CtrlVal(egt1_led)=1
Else
  CtrlVal(cht1_led)=1
  CtrlVal(egt1_led)=0
EndIf
End Sub

Sub TouchDown
'touch_state=Touch(ref)
'If touch_state>=1 And touch_state<=3 Then screen_state=touch_state
'Print touch_state screen_state
End Sub

Sub TouchUp
touch_state=Touch(lastref)
If touch_state>=1 And touch_state<=3 Then screen_state=touch_state
Print touch_state screen_state
End Sub

Sub redraw
  Select Case screen_state ' find out which control was touched
    Case status_button
      GUI hide status_button
      RBox 0,0,MM.FontWidth*7,MM.FontHeight*2,3,RGB(yellow),RGB(yellow)
      Text 10,12,"Status",L,5,1,RGB(black),RGB(yellow)
      If old_screen_state=data_button Then
        GUI restore data_button
        GUI hide cht_data_frame,egt_data_frame
        GUI hide cht1_data_box,cht2_data_box,cht3_data_box,cht4_data_box
        GUI hide egt1_data_box,egt2_data_box,egt3_data_box,egt4_data_box
      EndIf
      If old_screen_state=setup_button Then
        GUI restore setup_button
        GUI hide cht_thermo_type_frame,egt_thermo_type_frame
        GUI hide cht_jtype_button,cht_ktype_button
        GUI hide egt_jtype_button,egt_ktype_button
        GUI hide rpm_count_frame,rpm_dev2_button,rpm_even_button
        GUI hide rpm_mul2_button,rpm_mul4_button,rpm_dis_button
      EndIf
      GUI restore temps_stat_frame,cht_stat_box,egt_stat_box
      GUI restore cht1_led,cht2_led,cht3_led,cht4_led
      GUI restore egt1_led,egt2_led,egt3_led,egt4_led
    Case data_button
      GUI hide data_button
      RBox 127,0,MM.FontWidth*5,MM.FontHeight*2,3,RGB(yellow),RGB(yellow)
      Text 137,12,"Data",L,5,1,RGB(black),RGB(yellow)
      If old_screen_state=status_button Then
        GUI restore status_button
        GUI hide temps_stat_frame,cht_stat_box,egt_stat_box
        GUI hide cht1_led,cht2_led,cht3_led,cht4_led
        GUI hide egt1_led,egt2_led,egt3_led,egt4_led
      EndIf
      If old_screen_state=setup_button Then
        GUI restore setup_button
        GUI hide cht_thermo_type_frame,egt_thermo_type_frame
        GUI hide cht_jtype_button,cht_ktype_button
        GUI hide egt_jtype_button,egt_ktype_button
        GUI hide rpm_count_frame,rpm_dev2_button,rpm_even_button
        GUI hide rpm_mul2_button,rpm_mul4_button,rpm_dis_button
      EndIf
      GUI restore cht_data_frame,egt_data_frame
      GUI restore cht1_data_box,cht2_data_box,cht3_data_box,cht4_data_box
      GUI restore egt1_data_box,egt2_data_box,egt3_data_box,egt4_data_box
    Case setup_button
      GUI hide setup_button
      RBox 220,0,MM.FontWidth*6,MM.FontHeight*2,3,RGB(yellow),RGB(yellow)
      Text 230,12,"Setup",L,5,1,RGB(black),RGB(yellow)
      If old_screen_state=data_button Then
        GUI restore data_button
        GUI hide cht_data_frame,egt_data_frame
        GUI hide cht1_data_box,cht2_data_box,cht3_data_box,cht4_data_box
        GUI hide egt1_data_box,egt2_data_box,egt3_data_box,egt4_data_box
      EndIf
      If old_screen_state=status_button Then
        GUI restore status_button
        GUI hide temps_stat_frame,cht_stat_box,egt_stat_box
        GUI hide cht1_led,cht2_led,cht3_led,cht4_led
        GUI hide egt1_led,egt2_led,egt3_led,egt4_led
      EndIf
      GUI restore cht_thermo_type_frame,egt_thermo_type_frame
      GUI restore cht_jtype_button,cht_ktype_button
      GUI restore egt_jtype_button,egt_ktype_button
      GUI restore rpm_count_frame,rpm_dev2_button,rpm_even_button
      GUI restore rpm_mul2_button,rpm_mul4_button,rpm_dis_button
  End Select
  old_screen_state=screen_state ' update old
End Sub

End                                                                  